package com.ieslab.powergrid.demosvr.entity;

/** <p>Title: PersonService </p>
 * <p>Description: 通用Rest请求返回结构 </p>
 *
 * @author bingge
 * @date 2020-2-20 下午7:15:30
 * @version V1.0
 */
public class Result {
    //服务器返回的状态码(主要给程序员看)。例如 : 200 : 请求成功， 500 : 服务器内部错误，400 : 未知错误
    private Integer code;

    //返回码 1：成功  10000：系统错误 10001：参数错误  ...
    private Integer status;

    // 服务器的错误信息 ,主要返回给用户看
    private String msg;

    // 服务器返回的数据
    private Object data;

    public Result() {
    }

    //返回操作成功
    public static Result ok() {
        return ok(null);
    }

    //返回操作成功
    public static Result ok(Object data) {
        Result result = new Result();
        result.setCode(200);
        result.setStatus(1);
        result.setMsg("请求成功");
        result.setData(data);
        return result;
    }

    //返回操作成功
    public static Result error() {
        return error("请求失败");
    }

    //返回操作成功
    public static Result error(Integer code, Integer status, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setStatus(status);
        result.setMsg(msg);
        return result;
    }

    //返回操作成功
    public static Result error(String msg) {
        return error(500,0, msg);
    }

    //返回操作成功
    public static Result error(ErrorStatus errorStatus) {
        return error(500,errorStatus.value(), errorStatus.getMessage());
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
